<?php


namespace app\cms\community\thirdPartyApi\abstracts;


use app\cms\model\oauthConfigModel;

abstract class Config
{
    protected array $config = [];

    public CONST WECHAT_TYPE = 0;
    public CONST PAYPAL = 1;
    public CONST ALIPAY = 2;

    /**
     * @param int $type 平台类型 0 微信平台, 1 paypal 2 支付宝开放平台'
     * @param int $id 配置id 0 为默认配置
     * @throws \Exception
     */
    public function __construct(int $type = 0, int $id = 0) {

        $where = $id ? [ 'config_id' => $id ] : [ 'config_type' => $type, 'is_default' => 1 ];

        $config = (new oauthConfigModel) -> findInfo($where);
        if (empty($config)) throw new \Exception('获取基础配置失败， 配置不存在 config_id: '. $id);
        $this->config = array_merge($this->config, json_decode($config['config_info'], true));
    }

    public function getConfig(): array {
        return $this->config;
    }
}